******************************************************************************
*										
*                           Boese & Eberhardt							
*            
*                          Facets of Democracy
*													
******************************************************************************
*                   PCDID - heterogeneous model (1959-2018)
*			    (Specification with exports/trade & pop growth)
* 				           Low-level indices
******************************************************************************
*                                   Graphs 
*                       Using standardized thresholds 
******************************************************************************
*                           Created: 5th June 2024					
*                      Last Changed: 17th July 2024					
******************************************************************************
*                              Markus Eberhardt						
******************************************************************************
*                 School of Economics, University of Nottingham,			
*                  University Park, Nottingham NG7 2RD, England			
*                     email: markus.eberhardt@nottingham.ac.uk				
*                   web: https://sites.google.com/site/medevecon/			
******************************************************************************

*** This code produces
*** Figure 4, Panels (a) and (b)
*** Draft June 2024

clear all
set matsize 11000

***
*** Paths
***

global path "/Users/lezme/Dropbox/Facets of Democracy"
global rawpath "/Users/lezme/Dropbox"

global path "D:/Dropbox/Facets of Democracy"
global rawpath "D:/Dropbox"

global data "$path/Data"
global dofolder "$path/Do_files"
global otherdata "$path/Data"
global outputfolder "$path/Output"
global texfolder "$rawpath/Apps/Overleaf/Facets of Democracy/images"
global texfolder2 "$path/Tex"


global demo_list_full	"exp_neg25 exp_neg125 exp_0 exp_125 exp_25 assoc_neg25 assoc_neg125 assoc_0  assoc_125  assoc_25 fairel_neg25 fairel_neg125 fairel_0 fairel_125 fairel_25 rolaw_neg25 rolaw_neg125 rolaw_0 rolaw_125 rolaw_25 jucon_neg25 jucon_neg125 jucon_0 jucon_125 jucon_25 legon_neg25 legon_neg125 legon_0 legon_125 legon_25"


******	
***********
*********** Create low level moments 
***********
******


**** Get merged dataset and prepare variables
use "$data/madd_ert_vdem_2021.dta", clear
tsset nwbcode year

* Maddison: per capita GDP (in logs)*100 and population growth rate
gen y = ln(gdppc)*100
gen lpop = ln(pop)
gen dlpop = 100*d.lpop

* DOTS data: export/trade
gen ex = ex_trade*100

xtreg y dlpop ex v2x_libdem if year>1958, fe

drop csum 
gen c=1 if e(sample)
by nwbcode: egen csum=sum(c) if c==1
gen sample= (e(sample))

* V-Dem: democracy dummies from high and mid-level indicators
local z "_libdem _liberal _polyarchy _freexp_altinf _frassoc_thick el_frefair cl_rol _jucon lg_legcon _suffr _elecoff"
foreach k of local z{
	quietly{
	sum v2x`k' if sample==1
	scalar mean`k' = r(mean) 
	scalar sd`k' = r(sd) 
	gen st`k' = (v2x`k'-mean`k')/sd`k' if sample==1
	}
	di in ye "`k' --- Mean: " in gr r(mean)  in ye " and SD: " in gr r(sd)
}


* Positive values
local z "0"
foreach k of local z{
	local norm_`k' = `k'/100
	gen dem_poly_`k' = (st_polyarchy>=`norm_`k'') & !missing(v2x_polyarchy)
	gen dem_lib_`k' = (st_liberal>=`norm_`k'') & !missing(v2x_liberal)
	gen dem_exp_`k' = (st_freexp_altinf>=`norm_`k'') & !missing(v2x_freexp_altinf)
	label var dem_exp_`k' "Freedom of Expression Threshold > mean + .`k' sd"
	gen dem_assoc_`k' = (st_frassoc_thick>=`norm_`k'') & !missing(v2x_frassoc_thick)
	label var dem_assoc_`k' "Freedom of Association Threshold > mean + .`k' sd"
	gen dem_fairel_`k' = (stel_frefair>=`norm_`k'') & !missing(v2xel_frefair) 
	label var dem_fairel_`k' "Clean Election Threshold Threshold > mean + .`k' sd"
	gen dem_rolaw_`k' = (stcl_rol>=`norm_`k'') & !missing(v2xcl_rol)
	label var dem_rolaw_`k' "Rule of Law Threshold > mean + .`k' sd"
	gen dem_jucon_`k' = (st_jucon>=`norm_`k'') & !missing(v2x_jucon)
	label var dem_jucon_`k' "Jud. Constraints Threshold > mean + .`k' sd"
	gen dem_legcon_`k' = (stlg_legcon>=`norm_`k'') & !missing(v2xlg_legcon) 
	label var dem_legcon_`k' "Leg. Constraints Threshold > mean + .`k' sd"
	gen dem_suffr_`k' = (st_suffr>=`norm_`k'') & !missing(v2x_suffr) 
	label var dem_suffr_`k' "Suffrage Threshold > mean + .`k' sd"
	gen dem_elecoff_`k' = (st_elecoff>=`norm_`k'') & !missing(v2x_elecoff) 
	label var dem_elecoff_`k' "Elected Officials Threshold > mean + .`k' sd"
}

tab wbcode dem_suffr_0 if sample==1

gen demevent_poly = 1 if ((dem_poly_0==1 & l.dem_poly_0==0)) & sample==1
gen demevent_lib = 1 if ((dem_lib_0==1 & l.dem_lib_0==0)) & sample==1
replace demevent_poly = demevent_poly*st_liberal if sample==1
replace demevent_lib = demevent_lib*st_polyarchy if sample==1
gen demsd_poly = dem_poly_0*st_liberal if sample==1
gen demsd_lib = dem_lib_0*st_polyarchy if sample==1


* Low-level moments - STANDARDISED
gen demevent_exp = 1 if ((dem_exp_0==1 & l.dem_exp_0==0)) & sample==1
gen demevent_exp_lib = 1 if ((dem_exp_0==1 & l.dem_exp_0==0)) & sample==1
gen demevent_exp_assoc = 1 if ((dem_exp_0==1 & l.dem_exp_0==0)) & sample==1
gen demevent_exp_fairel = 1 if ((dem_exp_0==1 & l.dem_exp_0==0)) & sample==1
gen demevent_assoc = 1 if ((dem_assoc_0==1 & l.dem_assoc_0==0)) & sample==1
gen demevent_assoc_lib = 1 if ((dem_assoc_0==1 & l.dem_assoc_0==0)) & sample==1
gen demevent_assoc_exp = 1 if ((dem_assoc_0==1 & l.dem_assoc_0==0)) & sample==1
gen demevent_assoc_fairel = 1 if ((dem_assoc_0==1 & l.dem_assoc_0==0)) & sample==1
gen demevent_fairel = 1 if ((dem_fairel_0==1 & l.dem_fairel_0==0)) & sample==1
gen demevent_fairel_lib = 1 if ((dem_fairel_0==1 & l.dem_fairel_0==0)) & sample==1
gen demevent_fairel_exp = 1 if ((dem_fairel_0==1 & l.dem_fairel_0==0)) & sample==1
gen demevent_fairel_assoc = 1 if ((dem_fairel_0==1 & l.dem_fairel_0==0)) & sample==1
gen demevent_rolaw = 1 if ((dem_rolaw_0==1 & l.dem_rolaw_0==0)) & sample==1
gen demevent_rolaw_poly = 1 if ((dem_rolaw_0==1 & l.dem_rolaw_0==0)) & sample==1
gen demevent_rolaw_jucon = 1 if ((dem_rolaw_0==1 & l.dem_rolaw_0==0)) & sample==1
gen demevent_rolaw_legcon = 1 if ((dem_rolaw_0==1 & l.dem_rolaw_0==0)) & sample==1
gen demevent_jucon = 1 if ((dem_jucon_0==1 & l.dem_jucon_0==0)) & sample==1
gen demevent_jucon_poly = 1 if ((dem_jucon_0==1 & l.dem_jucon_0==0)) & sample==1
gen demevent_jucon_rolaw = 1 if ((dem_jucon_0==1 & l.dem_jucon_0==0)) & sample==1
gen demevent_jucon_legcon = 1 if ((dem_jucon_0==1 & l.dem_jucon_0==0)) & sample==1
gen demevent_legcon = 1 if ((dem_legcon_0==1 & l.dem_legcon_0==0)) & sample==1
gen demevent_legcon_poly = 1 if ((dem_legcon_0==1 & l.dem_legcon_0==0)) & sample==1
gen demevent_legcon_rolaw = 1 if ((dem_legcon_0==1 & l.dem_legcon_0==0)) & sample==1
gen demevent_legcon_jucon = 1 if ((dem_legcon_0==1 & l.dem_legcon_0==0)) & sample==1

* Controls for Freedom of Expression: liberal component, association, clean elections
replace demevent_exp_lib = demevent_exp*v2x_liberal if sample==1
replace demevent_exp_assoc = demevent_exp*v2x_frassoc_thick if sample==1
replace demevent_exp_fairel = demevent_exp*v2xel_frefair if sample==1
gen demsd_exp_lib = dem_exp_0*v2x_liberal if sample==1
gen demsd_exp_assoc = dem_exp_0*v2x_frassoc_thick if sample==1
gen demsd_exp_fairel = dem_exp_0*v2xel_frefair if sample==1

* Controls for Freedom of Association: liberal component, expression, clean elections
replace demevent_assoc_lib = demevent_assoc*st_liberal if sample==1
replace demevent_assoc_exp = demevent_assoc*st_freexp_altinf if sample==1
replace demevent_assoc_fairel = demevent_assoc*stel_frefair if sample==1
gen demsd_assoc_lib = dem_assoc_0*st_liberal if sample==1
gen demsd_assoc_exp = dem_assoc_0*st_freexp_altinf if sample==1
gen demsd_assoc_fairel = dem_assoc_0*stel_frefair if sample==1

* Controls for clean elections: liberal component, expression, association
replace demevent_fairel_lib = demevent_fairel*st_liberal if sample==1
replace demevent_fairel_exp = demevent_fairel*st_freexp_altinf if sample==1
replace demevent_fairel_assoc = demevent_fairel*st_frassoc_thick if sample==1
gen demsd_fairel_lib = dem_fairel_0*st_liberal if sample==1
gen demsd_fairel_exp = dem_fairel_0*st_freexp_altinf if sample==1
gen demsd_fairel_assoc = dem_fairel_0*st_frassoc_thick if sample==1

* Controls for rule of law: polyarchy, two executive constraints
replace demevent_rolaw_poly = demevent_rolaw*st_polyarchy if sample==1
replace demevent_rolaw_jucon = demevent_rolaw*st_jucon if sample==1
replace demevent_rolaw_legcon = demevent_rolaw*stlg_legcon if sample==1
gen demsd_rolaw_poly = dem_rolaw_0*st_polyarchy if sample==1
gen demsd_rolaw_jucon = dem_rolaw_0*st_jucon if sample==1
gen demsd_rolaw_legcon = dem_rolaw_0*stlg_legcon if sample==1

* Controls for judicial constraints: polyarchy, rule of law, legislative constraint
replace demevent_jucon_poly = demevent_jucon*st_polyarchy if sample==1
replace demevent_jucon_rolaw = demevent_jucon*stcl_rol if sample==1
replace demevent_jucon_legcon = demevent_jucon*stlg_legcon if sample==1
gen demsd_jucon_poly = dem_jucon_0*st_polyarchy if sample==1
gen demsd_jucon_rolaw = dem_jucon_0*stcl_rol if sample==1
gen demsd_jucon_legcon = dem_jucon_0*stlg_legcon if sample==1

* Controls for legislative constraints: polyarchy, rule of law, judicial constraint
replace demevent_legcon_poly = demevent_legcon*st_polyarchy if sample==1
replace demevent_legcon_rolaw = demevent_legcon*stcl_rol if sample==1
replace demevent_legcon_jucon = demevent_legcon*st_jucon if sample==1
gen demsd_legcon_poly = dem_legcon_0*st_polyarchy if sample==1
gen demsd_legcon_rolaw = dem_legcon_0*stcl_rol if sample==1
gen demsd_legcon_jucon = dem_legcon_0*st_jucon if sample==1

sort wbcode year
collapse ///
(mean) demevent_poly demevent_lib demevent_exp demevent_exp_lib demevent_exp_assoc demevent_exp_fairel demevent_assoc 	demevent_assoc_lib demevent_assoc_exp demevent_assoc_fairel demevent_fairel demevent_fairel_lib demevent_fairel_exp demevent_fairel_assoc demevent_rolaw demevent_rolaw_poly demevent_rolaw_jucon demevent_rolaw_legcon demevent_jucon demevent_jucon_poly demevent_jucon_rolaw demevent_jucon_legcon demevent_legcon demevent_legcon_poly demevent_legcon_rolaw demevent_legcon_jucon ///
(sd)  demsd_exp_lib demsd_exp_assoc demsd_exp_fairel demsd_assoc_lib demsd_assoc_exp demsd_assoc_fairel demsd_fairel_lib demsd_fairel_exp demsd_fairel_assoc demsd_rolaw_poly demsd_rolaw_jucon demsd_rolaw_legcon demsd_jucon_poly demsd_jucon_rolaw demsd_jucon_legcon demsd_legcon_poly demsd_legcon_rolaw demsd_legcon_jucon ///
, by(wbcode)
local z "exp_lib exp_assoc exp_fairel assoc_lib assoc_exp assoc_fairel fairel_lib fairel_exp fairel_assoc rolaw_poly rolaw_jucon rolaw_legcon jucon_poly jucon_rolaw jucon_legcon legcon_poly legcon_rolaw legcon_jucon"
foreach k of local z{
	replace demevent_`k' = 0 if demevent_`k'==.
}
sort wbcode
save "$data/low_level_st_moments_new.dta", replace 



******	
***********
*********** Horseraces 
***********
******


***
*** Low-level indicators: Polyarchy and the liberal component
***


use "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_exp_0_diagnostics_4.dta", clear 
rename beta1 beta
drop regime_def
local z "startyear endyear beta flips democratisations exposure total_obs nonexposure"
foreach k of local z{
	rename `k' `k'_exp
}
drop nwbcode 
merge wbcode using "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_assoc_0_diagnostics_4.dta", sort 
rename beta1 beta
drop regime_def _merge
local z "startyear endyear beta flips democratisations exposure total_obs nonexposure"
foreach k of local z{
	rename `k' `k'_assoc
}
merge wbcode using "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_fairel_0_diagnostics_4.dta", sort 
rename beta1 beta
drop regime_def _merge
local z "startyear endyear beta flips democratisations exposure total_obs nonexposure"
foreach k of local z{
	rename `k' `k'_fairel
}
merge wbcode using "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_rolaw_0_diagnostics_4.dta", sort 
rename beta1 beta
drop regime_def _merge
local z "startyear endyear beta flips democratisations exposure total_obs nonexposure"
foreach k of local z{
	rename `k' `k'_rolaw
}
merge wbcode using "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_jucon_0_diagnostics_4.dta", sort 
rename beta1 beta
drop regime_def _merge
drop if wbcode=="TUR" | wbcode=="PHL"
local z "startyear endyear beta flips democratisations exposure total_obs nonexposure"
foreach k of local z{
	rename `k' `k'_jucon
}
merge wbcode using "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_legon_0_diagnostics_4.dta", sort 
rename beta1 beta
drop regime_def _merge
*drop if wbcode=="DZA" | wbcode=="LBY" | wbcode=="EGY"
local z "startyear endyear beta flips democratisations exposure total_obs nonexposure"
foreach k of local z{
	rename `k' `k'_legcon
}

merge wbcode using "$data/low_level_st_moments_new.dta", sort
drop _merge

local z "exp assoc fairel rolaw jucon legcon"
foreach kk of local z{
	tab startyear_`kk', gen(by_) 
	mrunning beta_`kk' exposure_`kk' flips_`kk' demevent_`kk'_* demsd_`kk'_*, gen(changeX_) ci gense(changeseX_) adjust(by_*) nograph
	rename changeX_1 change_`kk'
	rename changeseX_1 changese_`kk'
	drop changeX_* changeseX_*
	gen tstat_`kk' = change_`kk'/changese_`kk'
	drop by_*
}


*** Horseraces (elements of polyarchy)
twoway ///
	(hist exposure_exp if !missing(change_exp), ///
		yaxis(2) w(5) start(0) freq fcolor(gs12%80) lcolor(gs12%80) barwidth(4.5)) /// 1
	(hist exposure_assoc if !missing(change_assoc), ///
		yaxis(2) w(5) start(0) freq fcolor(gs7%80) lcolor(gs7%80) barwidth(3)) /// 2
	(hist exposure_fairel if !missing(change_fairel), ///
		yaxis(2) w(5) start(0) freq fcolor(gs1%80) lcolor(gs1%80) barwidth(1.5)) /// 3
	(line change_exp exposure_exp, sort /// 
		lw(.8) lcolor(gold*1) lpattern(solid)) /// 4
	(scatter change_exp exposure_exp if abs(tstat_exp)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(gold*1.5%60) mlwidth(thin)) /// 5
	(scatter change_exp exposure_exp if abs(tstat_exp)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gold) mlcolor(gold*1.5%60) mlwidth(thin)) /// 6
	(line change_assoc exposure_assoc, sort ///
		lw(.8) lcolor(purple*1.5) lpattern(dash)) /// 7
	(scatter change_assoc exposure_assoc if abs(tstat_assoc)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(purple*1.5%60) mlwidth(thin)) /// 8
	(scatter change_assoc exposure_assoc if abs(tstat_assoc)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(purple) mlcolor(purple*1.5%60) mlwidth(thin)) /// 9
	(line change_fairel exposure_fairel, sort ///
		lw(.8) lcolor(orange*1.25) lpattern(shortdash)) /// 10
	(scatter change_fairel exposure_fairel if abs(tstat_fairel)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(orange*1.5%60) mlwidth(thin)) /// 11
	(scatter change_fairel exposure_fairel if abs(tstat_fairel)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(orange) mlcolor(orange*1.5%60) mlwidth(thin)) /// 12
, xsize(7) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Democracy (Length of Treatment)", size(small)) ///
	ytitle("Conditional Democracy Effect (in %)", size(small))  ///
	ytitle("Country Count", size(small) axis(2))  ///
	yscale(range(-15.1 30.1)) yscale(range(-.7 25) axis(2))   ///
	xmtick(##5) ymtick(##5, axis(2)) ///
	ylabel(-10(10)30, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	ylabel(0(5)20 25, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	xlabel(0(5)60, labsize(small)) graphregion(color(white)) ///
	legend(rows(3) order(- "Democracy Effect:" 4 7 10  - "Significant (10% level)" 6 9 12 - "Country Count (N):" 1 2 3) ///
	label(10 "Clean Elections > mean") label(7 "Association > mean") label(4 "Expression > mean") ///
	label(6 "")	label(9 "")		label(12 "") label(1 "(88)") label(2 "(82)") ///
	label(3 "(77)")	 size(small)  symxsize(*.5)) ///
	xline(5 55, lcolor(gs8) lwidth(.2) lp(shortdash))
graph export "$texfolder/PCDID_Maddison2024_low_levels_horseraces_poly_st.png", as(png) replace width(1200)
graph export "$texfolder/PCDID_Maddison2024_low_levels_horseraces_poly_st.eps", as(eps) replace


*** Horseraces (elements of the liberal component)
twoway ///
	(hist exposure_rolaw if !missing(change_rolaw), ///
		yaxis(2) w(5) start(0) freq fcolor(gs12%80) lcolor(gs12%80) barwidth(4.5)) /// 1
	(hist exposure_jucon if !missing(change_jucon), ///
		yaxis(2) w(5) start(0) freq fcolor(gs7%80) lcolor(gs7%80) barwidth(3)) /// 2
	(hist exposure_legcon if !missing(change_legcon), ///
		yaxis(2) w(5) start(0) freq fcolor(gs1%80) lcolor(gs1%80) barwidth(1.5)) /// 3
	(line change_rolaw exposure_rolaw, sort /// 
		lw(.8) lcolor(midblue*1) lpattern(solid)) /// 4
	(scatter change_rolaw exposure_rolaw if abs(tstat_rolaw)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(midblue*1.5%60) mlwidth(thin)) /// 5
	(scatter change_rolaw exposure_rolaw if abs(tstat_rolaw)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(midblue) mlcolor(midblue*1.5%60) mlwidth(thin)) /// 6
	(line change_jucon exposure_jucon, sort ///
		lw(.8) lcolor(pink*1.5) lpattern(dash)) /// 7
	(scatter change_jucon exposure_jucon if abs(tstat_jucon)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(pink*1.5%60) mlwidth(thin)) /// 8
	(scatter change_jucon exposure_jucon if abs(tstat_jucon)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(pink) mlcolor(pink*1.5%60) mlwidth(thin)) /// 9
	(line change_legcon exposure_legcon, sort ///
		lw(.8) lcolor(emerald*1.5) lpattern(shortdash)) /// 10
	(scatter change_legcon exposure_legcon if abs(tstat_legcon)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(emerald*1.5%60) mlwidth(thin)) /// 11
	(scatter change_legcon exposure_legcon if abs(tstat_legcon)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(emerald) mlcolor(emerald*1.5%60) mlwidth(thin)) /// 12
, xsize(7) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Democracy (Length of Treatment)", size(small)) ///
	ytitle("Conditional Democracy Effect (in %)", size(small))  ///
	ytitle("Country Count", size(small) axis(2))  yscale(range(-.65 15.35) axis(2)) ///
	yscale(range(-25.1 35.1))  xmtick(##5)  ///
	ylabel(-20(10)30, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	ylabel(0(2)14, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	xlabel(0(5)60, labsize(small)) graphregion(color(white)) ///
	legend(rows(3) order(- "Democracy Effect:" 4 7 10  - "Significant (10% level)" 6 9 12 - "Country Count (N):" 1 2 3) ///
	label(10 "Leg. Constraints > mean") label(7 "Jud. Constraints > mean") label(4 "Rule of Law > mean") ///
	label(6 "")	label(9 "")		label(12 "") label(1 "(78)") label(2 "(62)") ///
	label(3 "(76)")	 size(small)  symxsize(*.5)) ///
	xline(5 55, lcolor(gs8) lwidth(.2) lp(shortdash))
graph export "$texfolder/PCDID_Maddison2024_low_levels_horseraces_lib_st.png", as(png) replace width(1200)
graph export "$texfolder/PCDID_Maddison2024_low_levels_horseraces_lib_st.eps", as(eps) replace

tabstat total_obs_exp  total_obs_assoc total_obs_fairel, statistics(median)
tabstat exposure_exp  exposure_assoc exposure_fairel, statistics(median)

tabstat total_obs_rolaw total_obs_jucon total_obs_legcon, statistics(median)
tabstat exposure_rolaw exposure_jucon exposure_legcon, statistics(median)

******	
***********
*********** Multiple (low-level) indicators 
***********
******

****
**** Helper for moments
****	

use "$data/madd_ert_vdem_2021_helper.dta", clear 
tsset nwbcode year
keep if year>=1959 & year<=2018
sort nwbcode year
gen demevent_poly = 1 if ((dem_poly2==1 & l.dem_poly2==0)) & sample==1
gen demevent_lib = 1 if ((dem_lib2==1 & l.dem_lib2==0)) & sample==1
replace demevent_poly = demevent_poly*v2x_liberal if sample==1
replace demevent_lib = demevent_lib*v2x_polyarchy if sample==1
gen demsd_poly = dem_poly2*v2x_liberal if sample==1
gen demsd_lib = dem_lib2*v2x_polyarchy if sample==1

sort wbcode year
collapse (mean) demevent_poly demevent_lib (sd) demsd_poly demsd_lib, by(wbcode)
replace demsd_poly = . if demsd_poly==0
replace demsd_lib = . if demsd_lib==0
sort wbcode
save "$data/poly_lib_moments_new.dta", replace 
* Captures the polyarchy and liberal component index values in the year of democratisation.
* If there are more than one episode, it capures the mean.
* Also provides the std of the polyarchy and liberal component indeces during `democracy' (0.5 cutoff)
* demevent_poly has the liberal component values (mean) of the polyarchy threshold years
* demevent_lib has the polyarchy values (mean) of the liberal component threshold years
 

		
***
*** Graphs: Low-level indicator --- bring all results into the same format
***

local zz "$demo_list_full"
foreach kk of local zz{
	use "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_`kk'_diagnostics_4.dta", clear 
	rename beta1 beta
	drop regime_def
	local z "startyear endyear beta flips democratisations exposure total_obs nonexposure"
	foreach k of local z{
		rename `k' `k'_`kk'
	}
	save "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_`kk'_4c.dta", replace
}


***
*** Freedom of Expression
***

use "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_exp_neg25_4c.dta", clear
local zz "_neg125  _0 _125 _25"
foreach l of local zz{
	merge wbcode using "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_exp`l'_4c.dta", sort
	drop nwbcode _merge
}



local z "exp"
foreach kk of local z{
	local zz "_neg125 _neg25 _0 _125 _25"
	foreach k of local zz{
	tab startyear_`kk'`k', gen(by_)
	mrunning beta_`kk'`k' exposure_`kk'`k' flips_`kk'`k', gen(changeX_) adjust(by_*) ci gense(changeseX_)  nograph
	rename changeX_1 change_`kk'`k'
	rename changeseX_1 changese_`kk'`k'
	drop changeX_* changeseX_*
	gen tstat_`kk'`k' = change_`kk'`k'/changese_`kk'`k'
	drop by_*
	}
}

*** Graph
twoway ///
	(line change_exp_neg25 exposure_exp_neg25, sort ///
		lcolor(gs2%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_exp_neg25 exposure_exp_neg25 if abs(tstat_exp_neg25)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs2%60) mlwidth(thin)) ///
	(scatter change_exp_neg25 exposure_exp_neg25 if abs(tstat_exp_neg25)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs2%60) mlcolor(gs2%60) mlwidth(thin)) ///
	(line change_exp_neg125 exposure_exp_neg125, sort ///
		lcolor(gs5%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_exp_neg125 exposure_exp_neg125 if abs(tstat_exp_neg125)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs5%60) mlwidth(thin)) ///
	(scatter change_exp_neg125 exposure_exp_neg125 if abs(tstat_exp_neg125)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs5%60) mlcolor(gs5%60) mlwidth(thin)) ///
	(line change_exp_125 exposure_exp_125, sort ///
		lcolor(gs8%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_exp_125 exposure_exp_125 if abs(tstat_exp_125)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs8%60) mlwidth(thin)) ///
	(scatter change_exp_125 exposure_exp_125 if abs(tstat_exp_125)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs8%60) mlcolor(gs8%60) mlwidth(thin)) ///
	(line change_exp_25 exposure_exp_25, sort ///
		lcolor(gs11%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_exp_25 exposure_exp_25 if abs(tstat_exp_25)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs11%60) mlwidth(thin)) ///
	(scatter change_exp_25 exposure_exp_25 if abs(tstat_exp_25)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs11%60) mlcolor(gs11%60) mlwidth(thin)) ///
	(line change_exp_0 exposure_exp_0, sort yaxis(2) ///
		lcolor(gold*1) lwidth(.8) lpattern(solid)) ///
	(scatter change_exp_0 exposure_exp_0 if abs(tstat_exp_0)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(large) mfcolor(white%40) mlcolor(gold*1.5) mlwidth(thin)  yaxis(2)) ///
	(scatter change_exp_0 exposure_exp_0 if abs(tstat_exp_0)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(large) mfcolor(gold*1) mlcolor(gold*1.5) mlwidth(thin)  yaxis(2)) ///
, xsize(9) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Regime (Length of Treatment)", size(medsmall)) ///
	ytitle("Democracy Effect (in %)", size(medsmall))  ///
	yscale(range(-23.1 23.1)) yscale(range(-23.1 23.1) axis(2)) 	 ///
	ylabel(-20(5)20, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	ylabel(-20(5)20, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	xlabel(0(5)60, labsize(small)) graphregion(color(white)) ///
	ytitle("Democracy Effect (in %)", size(medsmall) axis(2))  ///
	xmtick(##5) ///
	legend(rows(2) order(- "Freedom of Expression Indicators for Cut-offs at" 1 4 13 7 10 - "Significant at 10% level (N)" ///
	3 6 15 9 12) ///
	label(1 "-1/4 sd")  label(4 "-1/8 sd") label(13 "mean") label(7 "+1/8 sd") label(10 "+1/4 sd") ///
	label(3 "(90)") label(6 "(89)") label(15 "(92)") label(9 "(94)") label(12 "(92)") ///
	size(medsmall) symxsize(*.5)) 
graph export "$texfolder/PCDID_Maddison2021_exp_multiple_st_alt.png", as(png) replace width(1200)
graph export "$texfolder/PCDID_Maddison2021_exp_multiple_st_alt.eps", as(eps) replace 



***
*** Freedom of Association
***

use "$outputfolder/PCDID_Maddison2021_Drilling_1949_2018_st_multiple_assoc_neg50_4c.dta", clear
local zz "_neg25 _neg125  _0 _125 _25 _50"
foreach l of local zz{
	merge wbcode using "$outputfolder/PCDID_Maddison2021_Drilling_1949_2018_st_multiple_assoc`l'_4c.dta", sort
	drop nwbcode _merge
}



local z "assoc"
foreach kk of local z{
	local zz "_neg50 _neg125 _neg25 _0 _125 _25 _50"
	foreach k of local zz{
	tab startyear_`kk'`k', gen(by_)
	mrunning beta_`kk'`k' exposure_`kk'`k' flips_`kk'`k', gen(changeX_) adjust(by_*) ci gense(changeseX_)  nograph
	rename changeX_1 change_`kk'`k'
	rename changeseX_1 changese_`kk'`k'
	drop changeX_* changeseX_*
	gen tstat_`kk'`k' = change_`kk'`k'/changese_`kk'`k'
	drop by_*
	}
}

*** ALTERNATIVE
twoway ///
	(line change_assoc_neg25 exposure_assoc_neg25, sort ///
		lcolor(gs2%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_assoc_neg25 exposure_assoc_neg25 if abs(tstat_assoc_neg25)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs2%60) mlwidth(thin)) ///
	(scatter change_assoc_neg25 exposure_assoc_neg25 if abs(tstat_assoc_neg25)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs2%60) mlcolor(gs2%60) mlwidth(thin)) ///
	(line change_assoc_neg125 exposure_assoc_neg125, sort ///
		lcolor(gs5%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_assoc_neg125 exposure_assoc_neg125 if abs(tstat_assoc_neg125)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs5%60) mlwidth(thin)) ///
	(scatter change_assoc_neg125 exposure_assoc_neg125 if abs(tstat_assoc_neg125)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs5%60) mlcolor(gs5%60) mlwidth(thin)) ///
	(line change_assoc_125 exposure_assoc_125, sort ///
		lcolor(gs8%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_assoc_125 exposure_assoc_125 if abs(tstat_assoc_125)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs8%60) mlwidth(thin)) ///
	(scatter change_assoc_125 exposure_assoc_125 if abs(tstat_assoc_125)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs8%60) mlcolor(gs8%60) mlwidth(thin)) ///
	(line change_assoc_25 exposure_assoc_25, sort ///
		lcolor(gs11%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_assoc_25 exposure_assoc_25 if abs(tstat_assoc_25)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs11%60) mlwidth(thin)) ///
	(scatter change_assoc_25 exposure_assoc_25 if abs(tstat_assoc_25)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs11%60) mlcolor(gs11%60) mlwidth(thin)) ///
	(line change_assoc_0 exposure_assoc_0, sort yaxis(2) ///
		lcolor(purple*1.25) lwidth(.8) lpattern(solid)) ///
	(scatter change_assoc_0 exposure_assoc_0 if abs(tstat_assoc_0)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(large) mfcolor(white%40) mlcolor(purple*1.5) mlwidth(thin)  yaxis(2)) ///
	(scatter change_assoc_0 exposure_assoc_0 if abs(tstat_assoc_0)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(large) mfcolor(purple*1) mlcolor(purple*1.5) mlwidth(thin)  yaxis(2)) ///
, xsize(9) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Regime (Length of Treatment)", size(medsmall)) ///
	ytitle("Democracy Effect (in %)", size(medsmall))  ///
	yscale(range(-3.1 25.1)) yscale(range(-3.1 25.1) axis(2)) 	 ///
	ylabel(-0(5)25, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	ylabel(-0(5)25, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	xlabel(0(5)70, labsize(small)) graphregion(color(white)) ///
	ytitle("Democracy Effect (in %)", size(medsmall) axis(2))  ///
	xmtick(##5) ///
	legend(rows(2) order(- "Freedom of Association Indicators for Cut-offs at" 1 4 13 7 10 - "Significant at 10% level (N)" ///
	3 6 15 9 12) ///
	label(1 "-1/4 sd")  label(4 "-1/8 sd") label(13 "mean") label(7 "+1/8 sd") label(10 "+1/4 sd") ///
	label(3 "(87)") label(6 "(88)") label(15 "(85)") label(9 "(84)") label(12 "(83)") ///
	size(medsmall) symxsize(*.5)) 
graph export "$texfolder/PCDID_Maddison2021_assoc_multiple_st_alt.png", as(png) replace width(1200)
graph export "$texfolder/PCDID_Maddison2021_assoc_multiple_st_alt.eps", as(eps) replace 

		
***
*** Free and Fair Elections
***


use "$outputfolder/PCDID_Maddison2021_Drilling_1949_2018_st_multiple_fairel_neg50_4c.dta", clear
local zz "_neg25 _neg125  _0 _125 _25 _50"
foreach l of local zz{
	merge wbcode using "$outputfolder/PCDID_Maddison2021_Drilling_1949_2018_st_multiple_fairel`l'_4c.dta", sort
	drop nwbcode _merge
}



local z "fairel"
foreach kk of local z{
	local zz "_neg50 _neg125 _neg25 _0 _125 _25 _50"
	foreach k of local zz{
	tab startyear_`kk'`k', gen(by_)
	mrunning beta_`kk'`k' exposure_`kk'`k' flips_`kk'`k', gen(changeX_) adjust(by_*) ci gense(changeseX_)  nograph
	rename changeX_1 change_`kk'`k'
	rename changeseX_1 changese_`kk'`k'
	drop changeX_* changeseX_*
	gen tstat_`kk'`k' = change_`kk'`k'/changese_`kk'`k'
	drop by_*
	}
}

*** ALTERNATIVE
twoway ///
	(line change_fairel_neg25 exposure_fairel_neg25, sort ///
		lcolor(gs2%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_fairel_neg25 exposure_fairel_neg25 if abs(tstat_fairel_neg25)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs2%60) mlwidth(thin)) ///
	(scatter change_fairel_neg25 exposure_fairel_neg25 if abs(tstat_fairel_neg25)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs2%60) mlcolor(gs2%60) mlwidth(thin)) ///
	(line change_fairel_neg125 exposure_fairel_neg125, sort ///
		lcolor(gs5%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_fairel_neg125 exposure_fairel_neg125 if abs(tstat_fairel_neg125)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs5%60) mlwidth(thin)) ///
	(scatter change_fairel_neg125 exposure_fairel_neg125 if abs(tstat_fairel_neg125)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs5%60) mlcolor(gs5%60) mlwidth(thin)) ///
	(line change_fairel_125 exposure_fairel_125, sort ///
		lcolor(gs8%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_fairel_125 exposure_fairel_125 if abs(tstat_fairel_125)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs8%60) mlwidth(thin)) ///
	(scatter change_fairel_125 exposure_fairel_125 if abs(tstat_fairel_125)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs8%60) mlcolor(gs8%60) mlwidth(thin)) ///
	(line change_fairel_25 exposure_fairel_25, sort ///
		lcolor(gs11%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_fairel_25 exposure_fairel_25 if abs(tstat_fairel_25)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs11%60) mlwidth(thin)) ///
	(scatter change_fairel_25 exposure_fairel_25 if abs(tstat_fairel_25)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs11%60) mlcolor(gs11%60) mlwidth(thin)) ///
	(line change_fairel_0 exposure_fairel_0, sort yaxis(2) ///
		lcolor(orange*1.25) lwidth(.8) lpattern(solid)) ///
	(scatter change_fairel_0 exposure_fairel_0 if abs(tstat_fairel_0)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(large) mfcolor(white%40) mlcolor(orange*1.5) mlwidth(thin)  yaxis(2)) ///
	(scatter change_fairel_0 exposure_fairel_0 if abs(tstat_fairel_0)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(large) mfcolor(orange*1) mlcolor(orange*1.5) mlwidth(thin)  yaxis(2)) ///
, xsize(9) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Regime (Length of Treatment)", size(medsmall)) ///
	ytitle("Democracy Effect (in %)", size(medsmall))  ///
	yscale(range(-7.1 35.1)) yscale(range(-7.1 35.1) axis(2)) 	 ///
	ylabel(-5(5)35, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	ylabel(-5(5)35, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	xlabel(0(5)70, labsize(small)) graphregion(color(white)) ///
	ytitle("Democracy Effect (in %)", size(medsmall) axis(2))  ///
	xmtick(##5) ///
	legend(rows(2) order(- "Clean Elections Indicators for Cut-offs at" 1 4 13 7 10 - "Significant at 10% level (N)" ///
	3 6 15 9 12) ///
	label(1 "-1/4 sd")  label(4 "-1/8 sd") label(13 "mean") label(7 "+1/8 sd") label(10 "+1/4 sd") ///
	label(3 "(91)") label(6 "(93)") label(15 "(82)") label(9 "(79)") label(12 "(71)") ///
	size(medsmall) symxsize(*.5)) 
graph export "$texfolder/PCDID_Maddison2021_fairel_multiple_st_alt.png", as(png) replace width(1200)
graph export "$texfolder/PCDID_Maddison2021_fairel_multiple_st_alt.eps", as(eps) replace 


***
*** Rule of Law
***


use "$outputfolder/PCDID_Maddison2021_Drilling_1949_2018_st_multiple_rolaw_neg50_4c.dta", clear
local zz "_neg25 _neg125  _0 _125 _25 _50"
foreach l of local zz{
	merge wbcode using "$outputfolder/PCDID_Maddison2021_Drilling_1949_2018_st_multiple_rolaw`l'_4c.dta", sort
	drop nwbcode _merge
}



local z "rolaw"
foreach kk of local z{
	local zz "_neg50 _neg125 _neg25 _0 _125 _25 _50"
	foreach k of local zz{
	tab startyear_`kk'`k', gen(by_)
	mrunning beta_`kk'`k' exposure_`kk'`k' flips_`kk'`k', gen(changeX_) adjust(by_*) ci gense(changeseX_)  nograph
	rename changeX_1 change_`kk'`k'
	rename changeseX_1 changese_`kk'`k'
	drop changeX_* changeseX_*
	gen tstat_`kk'`k' = change_`kk'`k'/changese_`kk'`k'
	drop by_*
	}
}

*** ALTERNATIVE
twoway ///
	(line change_rolaw_neg25 exposure_rolaw_neg25, sort ///
		lcolor(gs2%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_rolaw_neg25 exposure_rolaw_neg25 if abs(tstat_rolaw_neg25)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs2%60) mlwidth(thin)) ///
	(scatter change_rolaw_neg25 exposure_rolaw_neg25 if abs(tstat_rolaw_neg25)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs2%60) mlcolor(gs2%60) mlwidth(thin)) ///
	(line change_rolaw_neg125 exposure_rolaw_neg125, sort ///
		lcolor(gs5%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_rolaw_neg125 exposure_rolaw_neg125 if abs(tstat_rolaw_neg125)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs5%60) mlwidth(thin)) ///
	(scatter change_rolaw_neg125 exposure_rolaw_neg125 if abs(tstat_rolaw_neg125)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs5%60) mlcolor(gs5%60) mlwidth(thin)) ///
	(line change_rolaw_125 exposure_rolaw_125, sort ///
		lcolor(gs8%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_rolaw_125 exposure_rolaw_125 if abs(tstat_rolaw_125)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs8%60) mlwidth(thin)) ///
	(scatter change_rolaw_125 exposure_rolaw_125 if abs(tstat_rolaw_125)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs8%60) mlcolor(gs8%60) mlwidth(thin)) ///
	(line change_rolaw_25 exposure_rolaw_25 if exposure_rolaw_25<50, sort ///
		lcolor(gs11%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_rolaw_25 exposure_rolaw_25 if abs(tstat_rolaw_25)<1.645 & exposure_rolaw_25<50, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs11%60) mlwidth(thin)) ///
	(scatter change_rolaw_25 exposure_rolaw_25 if abs(tstat_rolaw_25)>1.645 & exposure_rolaw_25<50, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs11%60) mlcolor(gs11%60) mlwidth(thin)) ///
	(line change_rolaw_0 exposure_rolaw_0, sort yaxis(2) ///
		lcolor(midblue*1.25) lwidth(.8) lpattern(solid)) ///
	(scatter change_rolaw_0 exposure_rolaw_0 if abs(tstat_rolaw_0)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(large) mfcolor(white%40) mlcolor(midblue*1.5) mlwidth(thin)  yaxis(2)) ///
	(scatter change_rolaw_0 exposure_rolaw_0 if abs(tstat_rolaw_0)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(large) mfcolor(midblue*1) mlcolor(midblue*1.5) mlwidth(thin)  yaxis(2)) ///
, xsize(9) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Regime (Length of Treatment)", size(medsmall)) ///
	ytitle("Democracy Effect (in %)", size(medsmall))  ///
	yscale(range(-13.1 30.1)) yscale(range(-13.1 30.1) axis(2)) 	 ///
	ylabel(-10(5)30, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	ylabel(-10(5)30, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	xlabel(0(5)70, labsize(small)) graphregion(color(white)) ///
	ytitle("Democracy Effect (in %)", size(medsmall) axis(2))  ///
	xmtick(##5) ///
	legend(rows(2) order(- "Rule of Law Indicators for Cut-offs at" 1 4 13 7 10 - "Significant at 10% level (N)" ///
	3 6 15 9 12) ///
	label(1 "-1/4 sd")  label(4 "-1/8 sd") label(13 "mean") label(7 "+1/8 sd") label(10 "+1/4 sd") ///
	label(3 "(91)") label(6 "(93)") label(15 "(82)") label(9 "(79)") label(12 "(71)") ///
	size(medsmall) symxsize(*.5)) ///
	text(32 46.5 "*", color(gs0%60) place(center) just(center))
graph export "$texfolder/PCDID_Maddison2021_rolaw_multiple_st_alt.png", as(png) replace width(1200)
graph export "$texfolder/PCDID_Maddison2021_rolaw_multiple_st_alt.eps", as(eps) replace 

* HERE THE +12.5 sd graph is cut short to aid illustration ()

***
*** Judicial Constraints
***

use "$outputfolder/PCDID_Maddison2021_Drilling_1949_2018_st_multiple_jucon_neg50_4c.dta", clear
local zz "_neg25 _neg125  _0 _125 _25 _50"
foreach l of local zz{
	merge wbcode using "$outputfolder/PCDID_Maddison2021_Drilling_1949_2018_st_multiple_jucon`l'_4c.dta", sort
	drop nwbcode _merge
}



local z "jucon"
foreach kk of local z{
	local zz "_neg50 _neg125 _neg25 _0 _125 _25 _50"
	foreach k of local zz{
	tab startyear_`kk'`k', gen(by_)
	mrunning beta_`kk'`k' exposure_`kk'`k' flips_`kk'`k', gen(changeX_) adjust(by_*) ci gense(changeseX_)  nograph
	rename changeX_1 change_`kk'`k'
	rename changeseX_1 changese_`kk'`k'
	drop changeX_* changeseX_*
	gen tstat_`kk'`k' = change_`kk'`k'/changese_`kk'`k'
	drop by_*
	}
}

*** ALTERNATIVE
twoway ///
	(line change_jucon_neg25 exposure_jucon_neg25, sort ///
		lcolor(gs2%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_jucon_neg25 exposure_jucon_neg25 if abs(tstat_jucon_neg25)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs2%60) mlwidth(thin)) ///
	(scatter change_jucon_neg25 exposure_jucon_neg25 if abs(tstat_jucon_neg25)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs2%60) mlcolor(gs2%60) mlwidth(thin)) ///
	(line change_jucon_neg125 exposure_jucon_neg125, sort ///
		lcolor(gs5%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_jucon_neg125 exposure_jucon_neg125 if abs(tstat_jucon_neg125)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs5%60) mlwidth(thin)) ///
	(scatter change_jucon_neg125 exposure_jucon_neg125 if abs(tstat_jucon_neg125)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs5%60) mlcolor(gs5%60) mlwidth(thin)) ///
	(line change_jucon_125 exposure_jucon_125, sort ///
		lcolor(gs8%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_jucon_125 exposure_jucon_125 if abs(tstat_jucon_125)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs8%60) mlwidth(thin)) ///
	(scatter change_jucon_125 exposure_jucon_125 if abs(tstat_jucon_125)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs8%60) mlcolor(gs8%60) mlwidth(thin)) ///
	(line change_jucon_25 exposure_jucon_25, sort ///
		lcolor(gs11%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_jucon_25 exposure_jucon_25 if abs(tstat_jucon_25)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs11%60) mlwidth(thin)) ///
	(scatter change_jucon_25 exposure_jucon_25 if abs(tstat_jucon_25)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs11%60) mlcolor(gs11%60) mlwidth(thin)) ///
	(line change_jucon_0 exposure_jucon_0, sort yaxis(2) ///
		lcolor(pink*1.25) lwidth(.8) lpattern(solid)) ///
	(scatter change_jucon_0 exposure_jucon_0 if abs(tstat_jucon_0)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(large) mfcolor(white%40) mlcolor(pink*1.5) mlwidth(thin)  yaxis(2)) ///
	(scatter change_jucon_0 exposure_jucon_0 if abs(tstat_jucon_0)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(large) mfcolor(pink*1) mlcolor(pink*1.5) mlwidth(thin)  yaxis(2)) ///
, xsize(9) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Regime (Length of Treatment)", size(medsmall)) ///
	ytitle("Democracy Effect (in %)", size(medsmall))  ///
	yscale(range(-25.1 35.1)) yscale(range(-25.1 35.1) axis(2)) 	 ///
	ylabel(-20(10)30, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	ylabel(-20(10)30, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	xlabel(0(5)70, labsize(small)) graphregion(color(white)) ///
	ytitle("Democracy Effect (in %)", size(medsmall) axis(2))  ///
	xmtick(##5) ///
	legend(rows(2) order(- "Jud. Constraints Indicators for Cut-offs at" 1 4 13 7 10 - "Significant at 10% level (N)" ///
	3 6 15 9 12) ///
	label(1 "-1/4 sd")  label(4 "-1/8 sd") label(13 "mean") label(7 "+1/8 sd") label(10 "+1/4 sd") ///
	label(3 "(65)") label(6 "(63)") label(15 "(66)") label(9 "(63)") label(12 "(60)") ///
	size(medsmall) symxsize(*.5)) 
graph export "$texfolder/PCDID_Maddison2021_jucon_multiple_st_alt.png", as(png) replace width(1200)
graph export "$texfolder/PCDID_Maddison2021_jucon_multiple_st_alt.eps", as(eps) replace 

***
*** Legislative Constraints
***


use "$outputfolder/PCDID_Maddison2021_Drilling_1949_2018_st_multiple_legon_neg50_4c.dta", clear
local zz "_neg25 _neg125  _0 _125 _25 _50"
foreach l of local zz{
	merge wbcode using "$outputfolder/PCDID_Maddison2021_Drilling_1949_2018_st_multiple_legon`l'_4c.dta", sort
	drop nwbcode _merge
}



local z "legon"
foreach kk of local z{
	local zz "_neg50 _neg125 _neg25 _0 _125 _25 _50"
	foreach k of local zz{
	tab startyear_`kk'`k', gen(by_)
	mrunning beta_`kk'`k' exposure_`kk'`k' flips_`kk'`k', gen(changeX_) adjust(by_*) ci gense(changeseX_)  nograph
	rename changeX_1 change_`kk'`k'
	rename changeseX_1 changese_`kk'`k'
	drop changeX_* changeseX_*
	gen tstat_`kk'`k' = change_`kk'`k'/changese_`kk'`k'
	drop by_*
	}
}

*** ALTERNATIVE
twoway ///
	(line change_legon_neg25 exposure_legon_neg25, sort ///
		lcolor(gs2%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_legon_neg25 exposure_legon_neg25 if abs(tstat_legon_neg25)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs2%60) mlwidth(thin)) ///
	(scatter change_legon_neg25 exposure_legon_neg25 if abs(tstat_legon_neg25)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs2%60) mlcolor(gs2%60) mlwidth(thin)) ///
	(line change_legon_neg125 exposure_legon_neg125, sort ///
		lcolor(gs5%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_legon_neg125 exposure_legon_neg125 if abs(tstat_legon_neg125)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs5%60) mlwidth(thin)) ///
	(scatter change_legon_neg125 exposure_legon_neg125 if abs(tstat_legon_neg125)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs5%60) mlcolor(gs5%60) mlwidth(thin)) ///
	(line change_legon_125 exposure_legon_125, sort ///
		lcolor(gs8%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_legon_125 exposure_legon_125 if abs(tstat_legon_125)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs8%60) mlwidth(thin)) ///
	(scatter change_legon_125 exposure_legon_125 if abs(tstat_legon_125)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs8%60) mlcolor(gs8%60) mlwidth(thin)) ///
	(line change_legon_25 exposure_legon_25, sort ///
		lcolor(gs11%60) lwidth(.8) lpattern(solid)) ///
	(scatter change_legon_25 exposure_legon_25 if abs(tstat_legon_25)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%40) mlcolor(gs11%60) mlwidth(thin)) ///
	(scatter change_legon_25 exposure_legon_25 if abs(tstat_legon_25)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gs11%60) mlcolor(gs11%60) mlwidth(thin)) ///
	(line change_legon_0 exposure_legon_0, sort yaxis(2) ///
		lcolor(emerald*1.25) lwidth(.8) lpattern(solid)) ///
	(scatter change_legon_0 exposure_legon_0 if abs(tstat_legon_0)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(large) mfcolor(white%40) mlcolor(emerald*1.5) mlwidth(thin)  yaxis(2)) ///
	(scatter change_legon_0 exposure_legon_0 if abs(tstat_legon_0)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(large) mfcolor(emerald*1) mlcolor(emerald*1.5) mlwidth(thin)  yaxis(2)) ///
, xsize(9) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Regime (Length of Treatment)", size(medsmall)) ///
	ytitle("Democracy Effect (in %)", size(medsmall))  ///
	yscale(range(-30.1 30.1)) yscale(range(-25.1 30.1) axis(2)) 	 ///
	ylabel(-30(10)30, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	ylabel(-30(10)30, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	xlabel(0(5)70, labsize(small)) graphregion(color(white)) ///
	ytitle("Democracy Effect (in %)", size(medsmall) axis(2))  ///
	xmtick(##5) ///
	legend(rows(2) order(- "Leg. Constraints Indicators for Cut-offs at" 1 4 13 7 10 - "Significant at 10% level (N)" ///
	3 6 15 9 12) ///
	label(1 "-1/4 sd")  label(4 "-1/8 sd") label(13 "mean") label(7 "+1/8 sd") label(10 "+1/4 sd") ///
	label(3 "(86)") label(6 "(86)") label(15 "(83)") label(9 "(82)") label(12 "(81)") ///
	size(medsmall) symxsize(*.5)) 
graph export "$texfolder/PCDID_Maddison2021_legcon_multiple_st_alt.png", as(png) replace width(1200)
graph export "$texfolder/PCDID_Maddison2021_legcon_multiple_st_alt.eps", as(eps) replace 



**** EXPOSURE REGRESSIONS (time in regime)
local z "exp assoc fairel rolaw jucon legon"
foreach k of local z{
	quietly{
		use "$outputfolder/PCDID_Maddison2021_Drilling_1949_2018_st_multiple_`k'_0_4c.dta", clear
	*qreg exposure_`k'_0 if !missing(beta_`k'_0)
	qreg total_obs_`k'_0 if !missing(beta_`k'_0)
	}
	di in gr "Exposure for " in ye "`k'" in gr " is: " in ye _b[_cons] in gr " years."
}


******	
***********
*********** Low level horseraces: alternative cutoffs 
***********
******




***
*** Low-level indicators: Polyarchy and the liberal component
***

local sdvari "neg25 neg125 0 125 25"

foreach kkk of local sdvari{

	use "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_exp_`kkk'_diagnostics_4.dta", clear 
	rename beta1 beta
	drop regime_def
	local z "startyear endyear beta flips democratisations exposure total_obs nonexposure"
	foreach k of local z{
		rename `k' `k'_exp
	}
	drop nwbcode 
	merge wbcode using "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_assoc_`kkk'_diagnostics_4.dta", sort 
	rename beta1 beta
	drop regime_def _merge
	local z "startyear endyear beta flips democratisations exposure total_obs nonexposure"
	foreach k of local z{
		rename `k' `k'_assoc
	}
	merge wbcode using "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_fairel_`kkk'_diagnostics_4.dta", sort 
	rename beta1 beta
	drop regime_def _merge
	local z "startyear endyear beta flips democratisations exposure total_obs nonexposure"
	foreach k of local z{
		rename `k' `k'_fairel
	}
	merge wbcode using "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_rolaw_`kkk'_diagnostics_4.dta", sort 
	rename beta1 beta
	drop regime_def _merge
	local z "startyear endyear beta flips democratisations exposure total_obs nonexposure"
	foreach k of local z{
		rename `k' `k'_rolaw
	}
	merge wbcode using "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_jucon_`kkk'_diagnostics_4.dta", sort 
	rename beta1 beta
	drop regime_def _merge
	drop if wbcode=="TUR" | wbcode=="PHL"
	local z "startyear endyear beta flips democratisations exposure total_obs nonexposure"
	foreach k of local z{
		rename `k' `k'_jucon
	}
	merge wbcode using "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_st_multiple_legon_`kkk'_diagnostics_4.dta", sort 
	rename beta1 beta
	drop regime_def _merge
	local z "startyear endyear beta flips democratisations exposure total_obs nonexposure"
	foreach k of local z{
		rename `k' `k'_legcon
	}

	merge wbcode using "$data/low_level_st_moments_new.dta", sort
	drop _merge

	local z "exp assoc fairel rolaw jucon legcon"
	foreach kk of local z{
		tab startyear_`kk', gen(by_) 
		mrunning beta_`kk' exposure_`kk' flips_`kk' demevent_`kk'_* demsd_`kk'_*, gen(changeX_) ci gense(changeseX_) adjust(by_*) nograph
		rename changeX_1 change_`kk'
		rename changeseX_1 changese_`kk'
		drop changeX_* changeseX_*
		gen tstat_`kk' = change_`kk'/changese_`kk'
		drop by_*
	}

	save "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_low_level_st_`kkk'.dta", replace

}



***
*** Cutoff: mean - 1/4 SD
***

use "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_low_level_st_neg25.dta", replace

*** Horseraces (elements of polyarchy)
twoway ///
	(hist exposure_exp if !missing(change_exp), ///
		yaxis(2) w(5) start(0) freq fcolor(gs12%80) lcolor(gs12%80) barwidth(4.5)) /// 1
	(hist exposure_assoc if !missing(change_assoc), ///
		yaxis(2) w(5) start(0) freq fcolor(gs7%80) lcolor(gs7%80) barwidth(3)) /// 2
	(hist exposure_fairel if !missing(change_fairel), ///
		yaxis(2) w(5) start(0) freq fcolor(gs1%80) lcolor(gs1%80) barwidth(1.5)) /// 3
	(line change_exp exposure_exp, sort /// 
		lw(.8) lcolor(gold*1) lpattern(solid)) /// 4
	(scatter change_exp exposure_exp if abs(tstat_exp)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(gold*1.5%60) mlwidth(thin)) /// 5
	(scatter change_exp exposure_exp if abs(tstat_exp)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gold) mlcolor(gold*1.5%60) mlwidth(thin)) /// 6
	(line change_assoc exposure_assoc, sort ///
		lw(.8) lcolor(purple*1.5) lpattern(dash)) /// 7
	(scatter change_assoc exposure_assoc if abs(tstat_assoc)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(purple*1.5%60) mlwidth(thin)) /// 8
	(scatter change_assoc exposure_assoc if abs(tstat_assoc)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(purple) mlcolor(purple*1.5%60) mlwidth(thin)) /// 9
	(line change_fairel exposure_fairel, sort ///
		lw(.8) lcolor(orange*1.25) lpattern(shortdash)) /// 10
	(scatter change_fairel exposure_fairel if abs(tstat_fairel)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(orange*1.5%60) mlwidth(thin)) /// 11
	(scatter change_fairel exposure_fairel if abs(tstat_fairel)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(orange) mlcolor(orange*1.5%60) mlwidth(thin)) /// 12
, xsize(5) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Democracy (Length of Treatment)", size(small)) ///
	ytitle("Conditional Democracy Effect (in %)", size(small))  ///
	ytitle("Country Count", size(small) axis(2))  ///
	yscale(range(-20.1 40.1)) yscale(range(-.7 25) axis(2))   ///
	xmtick(##5) ymtick(##5, axis(2)) ///
	ylabel(-20(10)40, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	ylabel(0(5)20 25, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	xlabel(0(5)60, labsize(small)) graphregion(color(white) margin(tiny)) plotregion(margin(tiny))  ///
	legend(rows(3) order(- "Democracy Effect:" 4 7 10  - "Sign. (10% level)" 6 9 12 -  1 2 3) ///
	label(10 "Clean Elect.") label(7 "Assoc.") label(4 "Express'n") ///
	label(6 "")	label(9 "")		label(12 "") label(1 "") label(2 "") ///
	label(3 "")	 size(small)  symxsize(*.5)) ///
	xline(5 55, lcolor(gs8) lwidth(.2) lp(shortdash))
graph export "$texfolder/PCDID_Maddison2024_low_levels_horseraces_poly_st_neg25.eps", as(eps) replace


*** Horseraces (elements of the liberal component)
twoway ///
	(hist exposure_rolaw if !missing(change_rolaw), ///
		yaxis(2) w(5) start(0) freq fcolor(gs12%80) lcolor(gs12%80) barwidth(4.5)) /// 1
	(hist exposure_jucon if !missing(change_jucon), ///
		yaxis(2) w(5) start(0) freq fcolor(gs7%80) lcolor(gs7%80) barwidth(3)) /// 2
	(hist exposure_legcon if !missing(change_legcon), ///
		yaxis(2) w(5) start(0) freq fcolor(gs1%80) lcolor(gs1%80) barwidth(1.5)) /// 3
	(line change_rolaw exposure_rolaw, sort /// 
		lw(.8) lcolor(midblue*1) lpattern(solid)) /// 4
	(scatter change_rolaw exposure_rolaw if abs(tstat_rolaw)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(midblue*1.5%60) mlwidth(thin)) /// 5
	(scatter change_rolaw exposure_rolaw if abs(tstat_rolaw)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(midblue) mlcolor(midblue*1.5%60) mlwidth(thin)) /// 6
	(line change_jucon exposure_jucon, sort ///
		lw(.8) lcolor(pink*1.5) lpattern(dash)) /// 7
	(scatter change_jucon exposure_jucon if abs(tstat_jucon)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(pink*1.5%60) mlwidth(thin)) /// 8
	(scatter change_jucon exposure_jucon if abs(tstat_jucon)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(pink) mlcolor(pink*1.5%60) mlwidth(thin)) /// 9
	(line change_legcon exposure_legcon, sort ///
		lw(.8) lcolor(emerald*1.5) lpattern(shortdash)) /// 10
	(scatter change_legcon exposure_legcon if abs(tstat_legcon)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(emerald*1.5%60) mlwidth(thin)) /// 11
	(scatter change_legcon exposure_legcon if abs(tstat_legcon)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(emerald) mlcolor(emerald*1.5%60) mlwidth(thin)) /// 12
, xsize(5) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Democracy (Length of Treatment)", size(small)) ///
	ytitle("Conditional Democracy Effect (in %)", size(small))  ///
	ytitle("Country Count", size(small) axis(2))  yscale(range(-.65 15.35) axis(2)) ///
	yscale(range(-20.1 40.1))  xmtick(##5)  ///
	ylabel(-20(10)40, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	ylabel(0(2)14, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	xlabel(0(5)60, labsize(small)) graphregion(color(white)) ///
	legend(rows(3) order(- "Democracy Effect:" 4 7 10  - "Sign. (10% level)" 6 9 12 -  1 2 3) ///
	label(10 "Leg. Cons.") label(7 "Jud. Cons.") label(4 "Rule of Law") ///
	label(6 "")	label(9 "")		label(12 "") label(1 "") label(2 "") ///
	label(3 "")	 size(small)  symxsize(*.5)) ///
	xline(5 55, lcolor(gs8) lwidth(.2) lp(shortdash))
graph export "$texfolder/PCDID_Maddison2024_low_levels_horseraces_lib_st_neg25.eps", as(eps) replace



***
*** Cutoff: mean - 1/8 SD
***

use "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_low_level_st_neg125.dta", replace

*** Horseraces (elements of polyarchy)
twoway ///
	(hist exposure_exp if !missing(change_exp), ///
		yaxis(2) w(5) start(0) freq fcolor(gs12%80) lcolor(gs12%80) barwidth(4.5)) /// 1
	(hist exposure_assoc if !missing(change_assoc), ///
		yaxis(2) w(5) start(0) freq fcolor(gs7%80) lcolor(gs7%80) barwidth(3)) /// 2
	(hist exposure_fairel if !missing(change_fairel), ///
		yaxis(2) w(5) start(0) freq fcolor(gs1%80) lcolor(gs1%80) barwidth(1.5)) /// 3
	(line change_exp exposure_exp, sort /// 
		lw(.8) lcolor(gold*1) lpattern(solid)) /// 4
	(scatter change_exp exposure_exp if abs(tstat_exp)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(gold*1.5%60) mlwidth(thin)) /// 5
	(scatter change_exp exposure_exp if abs(tstat_exp)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gold) mlcolor(gold*1.5%60) mlwidth(thin)) /// 6
	(line change_assoc exposure_assoc, sort ///
		lw(.8) lcolor(purple*1.5) lpattern(dash)) /// 7
	(scatter change_assoc exposure_assoc if abs(tstat_assoc)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(purple*1.5%60) mlwidth(thin)) /// 8
	(scatter change_assoc exposure_assoc if abs(tstat_assoc)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(purple) mlcolor(purple*1.5%60) mlwidth(thin)) /// 9
	(line change_fairel exposure_fairel, sort ///
		lw(.8) lcolor(orange*1.25) lpattern(shortdash)) /// 10
	(scatter change_fairel exposure_fairel if abs(tstat_fairel)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(orange*1.5%60) mlwidth(thin)) /// 11
	(scatter change_fairel exposure_fairel if abs(tstat_fairel)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(orange) mlcolor(orange*1.5%60) mlwidth(thin)) /// 12
, xsize(5) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Democracy (Length of Treatment)", size(small)) ///
	ytitle("Conditional Democracy Effect (in %)", size(small))  ///
	ytitle("Country Count", size(small) axis(2))  ///
	yscale(range(-20.1 40.1)) yscale(range(-.7 25) axis(2))   ///
	xmtick(##5) ymtick(##5, axis(2)) ///
	ylabel(-20(10)40, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	ylabel(0(5)20 25, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	xlabel(0(5)60, labsize(small)) graphregion(color(white) margin(tiny)) plotregion(margin(tiny))  ///
	legend(rows(3) order(- "Democracy Effect:" 4 7 10  - "Sign. (10% level)" 6 9 12 -  1 2 3) ///
	label(10 "Clean Elect.") label(7 "Assoc.") label(4 "Express'n") ///
	label(6 "")	label(9 "")		label(12 "") label(1 "") label(2 "") ///
	label(3 "")	 size(small)  symxsize(*.5)) ///
	xline(5 55, lcolor(gs8) lwidth(.2) lp(shortdash))
graph export "$texfolder/PCDID_Maddison2024_low_levels_horseraces_poly_st_neg125.eps", as(eps) replace


*** Horseraces (elements of the liberal component)
twoway ///
	(hist exposure_rolaw if !missing(change_rolaw), ///
		yaxis(2) w(5) start(0) freq fcolor(gs12%80) lcolor(gs12%80) barwidth(4.5)) /// 1
	(hist exposure_jucon if !missing(change_jucon), ///
		yaxis(2) w(5) start(0) freq fcolor(gs7%80) lcolor(gs7%80) barwidth(3)) /// 2
	(hist exposure_legcon if !missing(change_legcon), ///
		yaxis(2) w(5) start(0) freq fcolor(gs1%80) lcolor(gs1%80) barwidth(1.5)) /// 3
	(line change_rolaw exposure_rolaw, sort /// 
		lw(.8) lcolor(midblue*1) lpattern(solid)) /// 4
	(scatter change_rolaw exposure_rolaw if abs(tstat_rolaw)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(midblue*1.5%60) mlwidth(thin)) /// 5
	(scatter change_rolaw exposure_rolaw if abs(tstat_rolaw)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(midblue) mlcolor(midblue*1.5%60) mlwidth(thin)) /// 6
	(line change_jucon exposure_jucon, sort ///
		lw(.8) lcolor(pink*1.5) lpattern(dash)) /// 7
	(scatter change_jucon exposure_jucon if abs(tstat_jucon)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(pink*1.5%60) mlwidth(thin)) /// 8
	(scatter change_jucon exposure_jucon if abs(tstat_jucon)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(pink) mlcolor(pink*1.5%60) mlwidth(thin)) /// 9
	(line change_legcon exposure_legcon, sort ///
		lw(.8) lcolor(emerald*1.5) lpattern(shortdash)) /// 10
	(scatter change_legcon exposure_legcon if abs(tstat_legcon)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(emerald*1.5%60) mlwidth(thin)) /// 11
	(scatter change_legcon exposure_legcon if abs(tstat_legcon)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(emerald) mlcolor(emerald*1.5%60) mlwidth(thin)) /// 12
, xsize(5) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Democracy (Length of Treatment)", size(small)) ///
	ytitle("Conditional Democracy Effect (in %)", size(small))  ///
	ytitle("Country Count", size(small) axis(2))  yscale(range(-.65 15.35) axis(2)) ///
	yscale(range(-20.1 40.1))  xmtick(##5)  ///
	ylabel(-20(10)40, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	ylabel(0(2)14, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	xlabel(0(5)60, labsize(small)) graphregion(color(white)) ///
	legend(rows(3) order(- "Democracy Effect:" 4 7 10  - "Sign. (10% level)" 6 9 12 -  1 2 3) ///
	label(10 "Leg. Cons.") label(7 "Jud. Cons.") label(4 "Rule of Law") ///
	label(6 "")	label(9 "")		label(12 "") label(1 "") label(2 "") ///
	label(3 "")	 size(small)  symxsize(*.5)) ///
	xline(5 55, lcolor(gs8) lwidth(.2) lp(shortdash))
graph export "$texfolder/PCDID_Maddison2024_low_levels_horseraces_lib_st_neg125.eps", as(eps) replace



***
*** Cutoff: mean
***

use "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_low_level_st_0.dta", replace

*** Horseraces (elements of polyarchy)
twoway ///
	(hist exposure_exp if !missing(change_exp), ///
		yaxis(2) w(5) start(0) freq fcolor(gs12%80) lcolor(gs12%80) barwidth(4.5)) /// 1
	(hist exposure_assoc if !missing(change_assoc), ///
		yaxis(2) w(5) start(0) freq fcolor(gs7%80) lcolor(gs7%80) barwidth(3)) /// 2
	(hist exposure_fairel if !missing(change_fairel), ///
		yaxis(2) w(5) start(0) freq fcolor(gs1%80) lcolor(gs1%80) barwidth(1.5)) /// 3
	(line change_exp exposure_exp, sort /// 
		lw(.8) lcolor(gold*1) lpattern(solid)) /// 4
	(scatter change_exp exposure_exp if abs(tstat_exp)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(gold*1.5%60) mlwidth(thin)) /// 5
	(scatter change_exp exposure_exp if abs(tstat_exp)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gold) mlcolor(gold*1.5%60) mlwidth(thin)) /// 6
	(line change_assoc exposure_assoc, sort ///
		lw(.8) lcolor(purple*1.5) lpattern(dash)) /// 7
	(scatter change_assoc exposure_assoc if abs(tstat_assoc)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(purple*1.5%60) mlwidth(thin)) /// 8
	(scatter change_assoc exposure_assoc if abs(tstat_assoc)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(purple) mlcolor(purple*1.5%60) mlwidth(thin)) /// 9
	(line change_fairel exposure_fairel, sort ///
		lw(.8) lcolor(orange*1.25) lpattern(shortdash)) /// 10
	(scatter change_fairel exposure_fairel if abs(tstat_fairel)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(orange*1.5%60) mlwidth(thin)) /// 11
	(scatter change_fairel exposure_fairel if abs(tstat_fairel)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(orange) mlcolor(orange*1.5%60) mlwidth(thin)) /// 12
, xsize(5) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Democracy (Length of Treatment)", size(small)) ///
	ytitle("Conditional Democracy Effect (in %)", size(small))  ///
	ytitle("Country Count", size(small) axis(2))  ///
	yscale(range(-20.1 40.1)) yscale(range(-.7 25) axis(2))   ///
	xmtick(##5) ymtick(##5, axis(2)) ///
	ylabel(-20(10)40, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	ylabel(0(5)20 25, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	xlabel(0(5)60, labsize(small)) graphregion(color(white) margin(tiny)) plotregion(margin(tiny))  ///
	legend(rows(3) order(- "Democracy Effect:" 4 7 10  - "Sign. (10% level)" 6 9 12 -  1 2 3) ///
	label(10 "Clean Elect.") label(7 "Assoc.") label(4 "Express'n") ///
	label(6 "")	label(9 "")		label(12 "") label(1 "") label(2 "") ///
	label(3 "")	 size(small)  symxsize(*.5)) ///
	xline(5 55, lcolor(gs8) lwidth(.2) lp(shortdash))
graph export "$texfolder/PCDID_Maddison2024_low_levels_horseraces_poly_st_mean.eps", as(eps) replace


*** Horseraces (elements of the liberal component)
twoway ///
	(hist exposure_rolaw if !missing(change_rolaw), ///
		yaxis(2) w(5) start(0) freq fcolor(gs12%80) lcolor(gs12%80) barwidth(4.5)) /// 1
	(hist exposure_jucon if !missing(change_jucon), ///
		yaxis(2) w(5) start(0) freq fcolor(gs7%80) lcolor(gs7%80) barwidth(3)) /// 2
	(hist exposure_legcon if !missing(change_legcon), ///
		yaxis(2) w(5) start(0) freq fcolor(gs1%80) lcolor(gs1%80) barwidth(1.5)) /// 3
	(line change_rolaw exposure_rolaw, sort /// 
		lw(.8) lcolor(midblue*1) lpattern(solid)) /// 4
	(scatter change_rolaw exposure_rolaw if abs(tstat_rolaw)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(midblue*1.5%60) mlwidth(thin)) /// 5
	(scatter change_rolaw exposure_rolaw if abs(tstat_rolaw)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(midblue) mlcolor(midblue*1.5%60) mlwidth(thin)) /// 6
	(line change_jucon exposure_jucon, sort ///
		lw(.8) lcolor(pink*1.5) lpattern(dash)) /// 7
	(scatter change_jucon exposure_jucon if abs(tstat_jucon)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(pink*1.5%60) mlwidth(thin)) /// 8
	(scatter change_jucon exposure_jucon if abs(tstat_jucon)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(pink) mlcolor(pink*1.5%60) mlwidth(thin)) /// 9
	(line change_legcon exposure_legcon, sort ///
		lw(.8) lcolor(emerald*1.5) lpattern(shortdash)) /// 10
	(scatter change_legcon exposure_legcon if abs(tstat_legcon)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(emerald*1.5%60) mlwidth(thin)) /// 11
	(scatter change_legcon exposure_legcon if abs(tstat_legcon)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(emerald) mlcolor(emerald*1.5%60) mlwidth(thin)) /// 12
, xsize(5) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Democracy (Length of Treatment)", size(small)) ///
	ytitle("Conditional Democracy Effect (in %)", size(small))  ///
	ytitle("Country Count", size(small) axis(2))  yscale(range(-.65 15.35) axis(2)) ///
	yscale(range(-20.1 40.1))  xmtick(##5)  ///
	ylabel(-20(10)40, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	ylabel(0(2)14, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	xlabel(0(5)60, labsize(small)) graphregion(color(white)) ///
	legend(rows(3) order(- "Democracy Effect:" 4 7 10  - "Sign. (10% level)" 6 9 12 -  1 2 3) ///
	label(10 "Leg. Cons.") label(7 "Jud. Cons.") label(4 "Rule of Law") ///
	label(6 "")	label(9 "")		label(12 "") label(1 "") label(2 "") ///
	label(3 "")	 size(small)  symxsize(*.5)) ///
	xline(5 55, lcolor(gs8) lwidth(.2) lp(shortdash))
graph export "$texfolder/PCDID_Maddison2024_low_levels_horseraces_lib_st_mean.eps", as(eps) replace


***
*** Cutoff: mean + 1/8 SD
***

use "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_low_level_st_125.dta", replace

*** Horseraces (elements of polyarchy)
twoway ///
	(hist exposure_exp if !missing(change_exp), ///
		yaxis(2) w(5) start(0) freq fcolor(gs12%80) lcolor(gs12%80) barwidth(4.5)) /// 1
	(hist exposure_assoc if !missing(change_assoc), ///
		yaxis(2) w(5) start(0) freq fcolor(gs7%80) lcolor(gs7%80) barwidth(3)) /// 2
	(hist exposure_fairel if !missing(change_fairel), ///
		yaxis(2) w(5) start(0) freq fcolor(gs1%80) lcolor(gs1%80) barwidth(1.5)) /// 3
	(line change_exp exposure_exp, sort /// 
		lw(.8) lcolor(gold*1) lpattern(solid)) /// 4
	(scatter change_exp exposure_exp if abs(tstat_exp)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(gold*1.5%60) mlwidth(thin)) /// 5
	(scatter change_exp exposure_exp if abs(tstat_exp)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gold) mlcolor(gold*1.5%60) mlwidth(thin)) /// 6
	(line change_assoc exposure_assoc, sort ///
		lw(.8) lcolor(purple*1.5) lpattern(dash)) /// 7
	(scatter change_assoc exposure_assoc if abs(tstat_assoc)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(purple*1.5%60) mlwidth(thin)) /// 8
	(scatter change_assoc exposure_assoc if abs(tstat_assoc)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(purple) mlcolor(purple*1.5%60) mlwidth(thin)) /// 9
	(line change_fairel exposure_fairel, sort ///
		lw(.8) lcolor(orange*1.25) lpattern(shortdash)) /// 10
	(scatter change_fairel exposure_fairel if abs(tstat_fairel)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(orange*1.5%60) mlwidth(thin)) /// 11
	(scatter change_fairel exposure_fairel if abs(tstat_fairel)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(orange) mlcolor(orange*1.5%60) mlwidth(thin)) /// 12
, xsize(5) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Democracy (Length of Treatment)", size(small)) ///
	ytitle("Conditional Democracy Effect (in %)", size(small))  ///
	ytitle("Country Count", size(small) axis(2))  ///
	yscale(range(-20.1 40.1)) yscale(range(-.7 25) axis(2))   ///
	xmtick(##5) ymtick(##5, axis(2)) ///
	ylabel(-20(10)40, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	ylabel(0(5)20 25, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	xlabel(0(5)60, labsize(small)) graphregion(color(white) margin(tiny)) plotregion(margin(tiny))  ///
	legend(rows(3) order(- "Democracy Effect:" 4 7 10  - "Sign. (10% level)" 6 9 12 -  1 2 3) ///
	label(10 "Clean Elect.") label(7 "Assoc.") label(4 "Express'n") ///
	label(6 "")	label(9 "")		label(12 "") label(1 "") label(2 "") ///
	label(3 "")	 size(small)  symxsize(*.5)) ///
	xline(5 55, lcolor(gs8) lwidth(.2) lp(shortdash))
graph export "$texfolder/PCDID_Maddison2024_low_levels_horseraces_poly_st_125.eps", as(eps) replace


*** Horseraces (elements of the liberal component)
twoway ///
	(hist exposure_rolaw if !missing(change_rolaw), ///
		yaxis(2) w(5) start(0) freq fcolor(gs12%80) lcolor(gs12%80) barwidth(4.5)) /// 1
	(hist exposure_jucon if !missing(change_jucon), ///
		yaxis(2) w(5) start(0) freq fcolor(gs7%80) lcolor(gs7%80) barwidth(3)) /// 2
	(hist exposure_legcon if !missing(change_legcon), ///
		yaxis(2) w(5) start(0) freq fcolor(gs1%80) lcolor(gs1%80) barwidth(1.5)) /// 3
	(line change_rolaw exposure_rolaw, sort /// 
		lw(.8) lcolor(midblue*1) lpattern(solid)) /// 4
	(scatter change_rolaw exposure_rolaw if abs(tstat_rolaw)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(midblue*1.5%60) mlwidth(thin)) /// 5
	(scatter change_rolaw exposure_rolaw if abs(tstat_rolaw)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(midblue) mlcolor(midblue*1.5%60) mlwidth(thin)) /// 6
	(line change_jucon exposure_jucon, sort ///
		lw(.8) lcolor(pink*1.5) lpattern(dash)) /// 7
	(scatter change_jucon exposure_jucon if abs(tstat_jucon)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(pink*1.5%60) mlwidth(thin)) /// 8
	(scatter change_jucon exposure_jucon if abs(tstat_jucon)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(pink) mlcolor(pink*1.5%60) mlwidth(thin)) /// 9
	(line change_legcon exposure_legcon, sort ///
		lw(.8) lcolor(emerald*1.5) lpattern(shortdash)) /// 10
	(scatter change_legcon exposure_legcon if abs(tstat_legcon)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(emerald*1.5%60) mlwidth(thin)) /// 11
	(scatter change_legcon exposure_legcon if abs(tstat_legcon)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(emerald) mlcolor(emerald*1.5%60) mlwidth(thin)) /// 12
, xsize(5) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Democracy (Length of Treatment)", size(small)) ///
	ytitle("Conditional Democracy Effect (in %)", size(small))  ///
	ytitle("Country Count", size(small) axis(2))  yscale(range(-.65 15.35) axis(2)) ///
	yscale(range(-25.1 40.1))  xmtick(##5)  ///
	ylabel(-20(10)40, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	ylabel(0(2)14, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	xlabel(0(5)60, labsize(small)) graphregion(color(white)) ///
	legend(rows(3) order(- "Democracy Effect:" 4 7 10  - "Sign. (10% level)" 6 9 12 -  1 2 3) ///
	label(10 "Leg. Cons.") label(7 "Jud. Cons.") label(4 "Rule of Law") ///
	label(6 "")	label(9 "")		label(12 "") label(1 "") label(2 "") ///
	label(3 "")	 size(small)  symxsize(*.5)) ///
	xline(5 55, lcolor(gs8) lwidth(.2) lp(shortdash))
graph export "$texfolder/PCDID_Maddison2024_low_levels_horseraces_lib_st_125.eps", as(eps) replace



***
*** Cutoff: mean + 1/4 SD
***

use "$outputfolder/PCDID_Maddison2024_Drilling_1959_2018_low_level_st_25.dta", replace

*** Horseraces (elements of polyarchy)
twoway ///
	(hist exposure_exp if !missing(change_exp), ///
		yaxis(2) w(5) start(0) freq fcolor(gs12%80) lcolor(gs12%80) barwidth(4.5)) /// 1
	(hist exposure_assoc if !missing(change_assoc), ///
		yaxis(2) w(5) start(0) freq fcolor(gs7%80) lcolor(gs7%80) barwidth(3)) /// 2
	(hist exposure_fairel if !missing(change_fairel), ///
		yaxis(2) w(5) start(0) freq fcolor(gs1%80) lcolor(gs1%80) barwidth(1.5)) /// 3
	(line change_exp exposure_exp, sort /// 
		lw(.8) lcolor(gold*1) lpattern(solid)) /// 4
	(scatter change_exp exposure_exp if abs(tstat_exp)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(gold*1.5%60) mlwidth(thin)) /// 5
	(scatter change_exp exposure_exp if abs(tstat_exp)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(gold) mlcolor(gold*1.5%60) mlwidth(thin)) /// 6
	(line change_assoc exposure_assoc, sort ///
		lw(.8) lcolor(purple*1.5) lpattern(dash)) /// 7
	(scatter change_assoc exposure_assoc if abs(tstat_assoc)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(purple*1.5%60) mlwidth(thin)) /// 8
	(scatter change_assoc exposure_assoc if abs(tstat_assoc)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(purple) mlcolor(purple*1.5%60) mlwidth(thin)) /// 9
	(line change_fairel exposure_fairel, sort ///
		lw(.8) lcolor(orange*1.25) lpattern(shortdash)) /// 10
	(scatter change_fairel exposure_fairel if abs(tstat_fairel)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(orange*1.5%60) mlwidth(thin)) /// 11
	(scatter change_fairel exposure_fairel if abs(tstat_fairel)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(orange) mlcolor(orange*1.5%60) mlwidth(thin)) /// 12
, xsize(5) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Democracy (Length of Treatment)", size(small)) ///
	ytitle("Conditional Democracy Effect (in %)", size(small))  ///
	ytitle("Country Count", size(small) axis(2))  ///
	yscale(range(-20.1 40.1)) yscale(range(-.7 25) axis(2))   ///
	xmtick(##5) ymtick(##5, axis(2)) ///
	ylabel(-20(10)40, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	ylabel(0(5)20 25, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	xlabel(0(5)60, labsize(small)) graphregion(color(white) margin(tiny)) plotregion(margin(tiny))  ///
	legend(rows(3) order(- "Democracy Effect:" 4 7 10  - "Sign. (10% level)" 6 9 12 -  1 2 3) ///
	label(10 "Clean Elect.") label(7 "Assoc.") label(4 "Express'n") ///
	label(6 "")	label(9 "")		label(12 "") label(1 "") label(2 "") ///
	label(3 "")	 size(small)  symxsize(*.5)) ///
	xline(5 55, lcolor(gs8) lwidth(.2) lp(shortdash))
graph export "$texfolder/PCDID_Maddison2024_low_levels_horseraces_poly_st_25.eps", as(eps) replace


*** Horseraces (elements of the liberal component)
twoway ///
	(hist exposure_rolaw if !missing(change_rolaw), ///
		yaxis(2) w(5) start(0) freq fcolor(gs12%80) lcolor(gs12%80) barwidth(4.5)) /// 1
	(hist exposure_jucon if !missing(change_jucon), ///
		yaxis(2) w(5) start(0) freq fcolor(gs7%80) lcolor(gs7%80) barwidth(3)) /// 2
	(hist exposure_legcon if !missing(change_legcon), ///
		yaxis(2) w(5) start(0) freq fcolor(gs1%80) lcolor(gs1%80) barwidth(1.5)) /// 3
	(line change_rolaw exposure_rolaw, sort /// 
		lw(.8) lcolor(midblue*1) lpattern(solid)) /// 4
	(scatter change_rolaw exposure_rolaw if abs(tstat_rolaw)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(midblue*1.5%60) mlwidth(thin)) /// 5
	(scatter change_rolaw exposure_rolaw if abs(tstat_rolaw)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(midblue) mlcolor(midblue*1.5%60) mlwidth(thin)) /// 6
	(line change_jucon exposure_jucon, sort ///
		lw(.8) lcolor(pink*1.5) lpattern(dash)) /// 7
	(scatter change_jucon exposure_jucon if abs(tstat_jucon)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(pink*1.5%60) mlwidth(thin)) /// 8
	(scatter change_jucon exposure_jucon if abs(tstat_jucon)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(pink) mlcolor(pink*1.5%60) mlwidth(thin)) /// 9
	(line change_legcon exposure_legcon, sort ///
		lw(.8) lcolor(emerald*1.5) lpattern(shortdash)) /// 10
	(scatter change_legcon exposure_legcon if abs(tstat_legcon)<1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(white%60) mlcolor(emerald*1.5%60) mlwidth(thin)) /// 11
	(scatter change_legcon exposure_legcon if abs(tstat_legcon)>1.645, sort jitterseed(280115) jitter(2) ///
		 msymbol(O)  msize(medlarge) mfcolor(emerald) mlcolor(emerald*1.5%60) mlwidth(thin)) /// 12
, xsize(5) ysize(4) scheme(s2mono) yline(0, lpattern(shortdash) lw(.4) lcolor(black)) ///
	xtitle("Years Spent in Democracy (Length of Treatment)", size(small)) ///
	ytitle("Conditional Democracy Effect (in %)", size(small))  ///
	ytitle("Country Count", size(small) axis(2))  yscale(range(-.65 15.35) axis(2)) ///
	yscale(range(-25.1 40.1))  xmtick(##5)  ///
	ylabel(-20(10)40, labsize(small) glcolor(gs8) grid glwidth(.2) glp(shortdash)  angle(0)) ///
	ylabel(0(2)14, labsize(small) glcolor(gs8) angle(0) axis(2)) ///
	xlabel(0(5)60, labsize(small)) graphregion(color(white)) ///
	legend(rows(3) order(- "Democracy Effect:" 4 7 10  - "Sign. (10% level)" 6 9 12 -  1 2 3) ///
	label(10 "Leg. Cons.") label(7 "Jud. Cons.") label(4 "Rule of Law") ///
	label(6 "")	label(9 "")		label(12 "") label(1 "") label(2 "") ///
	label(3 "")	 size(small)  symxsize(*.5)) ///
	xline(5 55, lcolor(gs8) lwidth(.2) lp(shortdash))
graph export "$texfolder/PCDID_Maddison2024_low_levels_horseraces_lib_st_25.eps", as(eps) replace


	